
package net.vinote.smart.platform.service.dw.html;

import java.util.Map;

import net.vinote.smart.platform.service.SRE;
import net.vinote.smart.platform.service.bean.CodeLibrary;


public class InputRadioGroupTag extends HtmlTag
{
	private String htmlTemplate = "<ul class='radioGroup'>#content</ul>";

	public InputRadioGroupTag(HtmlTag htmlTag)
	{
		super(htmlTag);
	}

	@Override
	protected String getHtmlTemplate()
	{
		return htmlTemplate;
	}

	@Override
	protected void initPlaceHolder()
	{
		if ("Code".equals(getHtmlSource()))
		{
			addContent(getRadiosByCode());
		}
		placeholder.put("#content", getContent());
	}

	private String getRadiosByCode()
	{
		StringBuffer sb = new StringBuffer();
		Map<String, CodeLibrary> codeItemMap = SRE.getCodeItems(getHtmlVal());
		int index = 0;
		if (codeItemMap != null)
		{
			for (String itemNo : codeItemMap.keySet())
			{
				InputRadioTag tag = new InputRadioTag(this.clone());
				tag.removeAttribute("id");
				tag.setId(tag.getName() + index++);
				tag.setChecked(itemNo.equals(getValue()));
				tag.setValue(itemNo);
				tag.setShowValue(codeItemMap.get(itemNo).getItemName());
				sb.append("<li>").append(tag.getHtml()).append("</li>");
			}
		}
		return sb.toString();
	}

}
